import React from "react";

class Vote extends React.Component {
    // constructor(props) {
    //     super(props); // 会把传来的数据挂载到this上
    // }
    state = {
        supNum:10,
        oppNum:5
    }
    static defaultProps = {
        title:'Vote'
    }
    render() {
        let {title} = this.props,
            {supNum,oppNum} = this.state
        return (
            <div>
                <h1>{title}</h1>
                <div>支持人数: {supNum}</div>
                <div>反对人数: {oppNum}</div>
                <div>sum:{supNum+oppNum}</div>
                <button onClick={() => { 
                    /* 通过的是react原型上的方法实现 */
                    this.setState({
                        supNum:supNum+1
                    })
                }}>支持</button>
                <button onClick={()=>{

                }}>反对</button>
            </div>
        )
    }
}

export default Vote;